﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Text;
using GreatB2C.Utility;
using GreatB2C.Business;

namespace GreatB2C.Web.Manage.SystemSet.Contents
{
    public partial class Field : Inherit.ManagePage
    {
        Business.Model BLL = new Business.Model( );

        protected void Page_Load( object sender , EventArgs e )
        {
            if ( !IsPostBack )
            {
                drShowStyleSet.DataInitial( );

                // 默认单行文本
                radTextType.Checked = true;
                radlFieldType_SelectedIndexChanged( sender , e );

                trCMS.Visible = true;

                // 禁止设置该字段值的会员组
                Business.UserGroups groupsBLL = new UserGroups( );
                DataTable dtGroups = groupsBLL.ListUserGroups( );
                if ( dtGroups != null && dtGroups.Rows.Count > 0 )
                {
                    chkGroupList.DataSource = dtGroups;
                    chkGroupList.DataTextField = "GroupName";
                    chkGroupList.DataValueField = "GroupID";
                    chkGroupList.DataBind( );
                }

                // 禁止设置该字段值的角色
                Business.Roles roleBLL = new Roles( );
                DataTable dtRoles = roleBLL.ListRoles( );
                if ( dtRoles != null && dtRoles.Rows.Count > 0 )
                {
                    chkRoleList.DataSource = dtRoles;
                    chkRoleList.DataTextField = "RoleName";
                    chkRoleList.DataValueField = "RoleID";
                    chkRoleList.DataBind( );
                }

                // 默认字段类型
                ViewState[ "FieldType" ] = DataDefine.FieldType.TextType;

                // 获取信息来自模型
                DataTable dtModel = BLL.ListModel( );
                if ( dtModel != null && dtModel.Rows.Count > 0 )
                {
                    ddlLookupTable.DataSource = dtModel;
                    ddlLookupTable.DataTextField = "ModelName";
                    ddlLookupTable.DataValueField = "ModelId";
                    ddlLookupTable.DataBind( );
                }

                ddlLookupField.Items.Insert( 0 , new ListItem( "-请选择模型-" , "" ) );
                ddlLookupField.Items.Add( new ListItem( "-请选择字段-" , "" ) );                
            }
        }

        protected void BtnSubmit_Click( object sender , EventArgs e )
        {
            if ( ViewState[ "FieldType" ] != null )
            {
                StringBuilder sbField = new StringBuilder( );

                GreatB2C.Model.Model model = new GreatB2C.Model.Model( );
                model.ModelID = Convert.ToInt32( Request.QueryString[ "ModelId" ].ToString( ) );
                model = BLL.ListByID( model );
                if ( model == null )
                {
                    litScript.Text = "<script type='text/javascript'>ShowErrorAndRedirect('操作失败','模板信息不存在！','ModelManage.aspx');</script>";
                    return;
                }

                Component.DefaultTemplateFields dtf = new GreatB2C.Web.Component.DefaultTemplateFields( );
                dtf.Field = model.Field;
                DataTable dtFields = dtf.GetDataTable( "" );
                DataView dv = dtFields.DefaultView;
                dv.Sort = "OrderID desc";
                int maxOrder = Convert.ToInt32( dv[ 0 ][ "OrderID" ].ToString( ) );

                string FieldName = txtFieldName.Text.Trim( );
                string FieldAliax = txtFieldAliax.Text.Trim( );
                string Tips = txtTips.Text.Trim( );
                string Description = txtDescription.Text.Trim( );
                string EnableNull = radlEnableNull.SelectedValue.Trim( );
                string EnableShowOnSearchForm = radlEnableShowOnSearchForm.SelectedValue.Trim( );
                string Disabled = radDisabled.SelectedValue.Trim( );
                string EnableFilter = radlEnableFilter.SelectedValue.Trim( );

                sbField.Append( "<FieldInfo Id=\"" + FieldName + "\" Disabled=\"" + Disabled + "\" OrderId=\"" + ( maxOrder + 1 ).ToString( ) + "\">" + DataDefine.NewLine );
                sbField.Append( "   <FieldName>" + FieldName + "</FieldName>" + DataDefine.NewLine );
                sbField.Append( "   <EnableShowOnSearchForm>" + EnableShowOnSearchForm + "</EnableShowOnSearchForm>" + DataDefine.NewLine );
                sbField.Append( "   <EnableFilter>" + EnableFilter + "</EnableFilter>" + DataDefine.NewLine );
                sbField.Append( "   <FieldAlias>" + FieldAliax + "</FieldAlias>" + DataDefine.NewLine );
                sbField.Append( "   <FieldLevel>1</FieldLevel>" + DataDefine.NewLine );
                sbField.Append( "   <Tips>" + Tips + "</Tips>" + DataDefine.NewLine );
                sbField.Append( "   <Description>" + Description + "</Description>" + DataDefine.NewLine );

                DataDefine.FieldType ftype = ( DataDefine.FieldType )ViewState[ "FieldType" ];
                switch ( ftype )
                {
                    /// <summary>
                    /// 单行文本
                    /// </summary>
                    case DataDefine.FieldType.TextType:
                        sbField.Append( "   <FieldType>" + DataDefine.FieldType.TextType.ToString( ) + "</FieldType>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtTextMaxLength.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtTextSize.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>False</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + ddlTextIMEMode.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlSiteLink.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlCharFilter.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlCharShield.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + ddlTextBoxRegexRule.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtRegexErrorMsg.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue>" + txtTextDefaultValue.Text.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 多行文本（不支持HTML）
                    /// </summary>
                    case DataDefine.FieldType.MultipleTextType:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtMultiTextWidth.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtMultiTextRow.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlSiteLink.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlCharFilter.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlCharShield.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue>" + txtMultiDefault.Text.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 多行文本（支持HTML）
                    /// </summary>
                    case DataDefine.FieldType.MultipleHtmlTextType:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + ddlEditorType.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtEditorWidth.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtEditorHight.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlSiteLink.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlCharFilter.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlCharShield.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue>" + txtMulitHtmlDefault.Text.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 选项
                    /// </summary>
                    case DataDefine.FieldType.ListBoxType:
                        {
                            string choise = "";
                            bool isExist = false;
                            foreach ( ListItem li in lstChoise.Items )
                            {
                                if ( choise.Trim( ).Length > 0 )
                                    choise += "$$$";

                                choise += li.Text;

                                string val = li.Text.Trim( ).Substring( li.Text.Trim( ).IndexOf( "|" ) + 1 );
                                if ( val.Trim( ) == txtChoiceDefaultValue.Text.Trim( ) )
                                {
                                    isExist = true;
                                }
                            }

                            if ( !isExist )
                            {
                                litScript.Text = "<script type='text/javascript'>ShowError('错误','“选项”域的默认值必须从指定的选项中选择。请再试一次！');</script>";
                                return;
                            }

                            sbField.Append( "   <Settings>" + DataDefine.NewLine );
                            sbField.Append( "       <string>" + choise + "</string>" + DataDefine.NewLine );
                            sbField.Append( "       <string>" + radlChoiceType.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                            sbField.Append( "       <string>" + radlEnableFill.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                            sbField.Append( "       <string>" + txtRepeatColumns.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                            sbField.Append( "   <Settings>" + DataDefine.NewLine );
                            sbField.Append( "   <DefaultValue>" + txtChoiceDefaultValue.Text.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        }
                        break;
                    /// <summary>
                    /// 数字
                    /// </summary>
                    case DataDefine.FieldType.NumberType:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtNumberMinLength.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtNumberMaxlength.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + ddlNumberDecimals.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + chkNumberPercent.Checked.ToString( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue>" + txtNumberDefaultValue.Text.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 货币
                    /// </summary>
                    case DataDefine.FieldType.MoneyType:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtCurrencyMinLength.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtCurrencyMaxLength.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue>" + txtCurrencyDefaultValue.Text.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 日期和时间
                    /// </summary>
                    case DataDefine.FieldType.DateTimeType:
                        {
                            string defaultval = "";
                            if ( radlDateTimeDefaultType.SelectedValue.Trim( ) == "2" )
                            {
                                defaultval = txtOrderDate.Text.Trim( );
                            }

                            if ( defaultval.Trim( ) == "" )
                            {
                                defaultval = DateTime.Now.ToString( "yyyy-MM-dd HH:mm" );
                            }

                            sbField.Append( "   <Settings>" + DataDefine.NewLine );
                            sbField.Append( "       <string>" + radioDateTimeType.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                            sbField.Append( "       <string>" + radlDateTimeDefaultType.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                            sbField.Append( "   <Settings>" + DataDefine.NewLine );
                            sbField.Append( "   <DefaultValue>" + defaultval + "</DefaultValue>" + DataDefine.NewLine );
                        }
                        break;
                    /// <summary>
                    /// 查阅项
                    /// </summary>
                    case DataDefine.FieldType.LookType:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + ddlLookupTable.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + ddlLookupField.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue></DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 超链接
                    /// </summary>
                    case DataDefine.FieldType.LinkType:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtURLMaxLength.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtURLSize.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue>" + txtURLDefaultValue.Text.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 是/否（复选框）
                    /// </summary>
                    case DataDefine.FieldType.BoolType:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + ddlBoolean.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue>" + ddlBoolean.SelectedValue.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 图片
                    /// </summary>
                    case DataDefine.FieldType.PictureType:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtImageTextLength.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtImageSize.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtImageType.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + ddlImageNameRule.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radioImageIsUseSilverlight.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlIsFromSelected.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlUploadFiles.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlWsImage.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlThumb.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue>" + txtPicDefaultUrl.Text.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 文件
                    /// </summary>
                    case DataDefine.FieldType.FileType:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtFileSize.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtFileType.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + chkDownLoadUrl.Checked.ToString( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + chkSoftSize.Checked.ToString( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtFileSizeField.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + ddlFileNameRule.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtFileUrlPrdfix.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radFileIsUseSilverlight.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue>" + txtFileDefaultValue.Text.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 颜色代码
                    /// </summary>
                    case DataDefine.FieldType.ColorType:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtColorDefault.Value.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue>" + txtColorDefault.Value.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 运行平台
                    /// </summary>
                    case DataDefine.FieldType.OperatingType:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtOperatingSystemSelectItem.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtOperatingSystemSize.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radOperatingIsPCookie.SelectedValue.ToString( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue>" + txtOperatingSystemDefaultValue.Text.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 行政区划
                    /// </summary>
                    case DataDefine.FieldType.RegionType:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radRegionDirection.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radRegionShow.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        switch ( radRegionShow.SelectedValue.Trim( ) )
                        {
                            case "1":   // 国家+省
                                sbField.Append( "       <string>" + drShowStyleSet.Nation + "," + drShowStyleSet.Province + "</string>" + DataDefine.NewLine );
                                break;
                            case "2":   // 国家+省+市
                                sbField.Append( "       <string>" + drShowStyleSet.Nation + "," + drShowStyleSet.Province + drShowStyleSet.City + "</string>" + DataDefine.NewLine );
                                break;
                            case "3":   // 国家+省+市+县
                                sbField.Append( "       <string>" + drShowStyleSet.Nation + "," + drShowStyleSet.Province + drShowStyleSet.City + "," + drShowStyleSet.Area + "</string>" + DataDefine.NewLine );
                                break;
                            case "4":   // 省+市
                                sbField.Append( "       <string>" + drShowStyleSet.Province + drShowStyleSet.City + "</string>" + DataDefine.NewLine );
                                break;
                            case "5":   // 省+市+县
                                sbField.Append( "       <string>" + drShowStyleSet.Province + drShowStyleSet.City + "," + drShowStyleSet.Area + "</string>" + DataDefine.NewLine );
                                break;
                            case "6":   // 市+县
                                sbField.Append( "       <string>" + drShowStyleSet.City + "," + drShowStyleSet.Area + "</string>" + DataDefine.NewLine );
                                break;
                        }
                        sbField.Append( "       <string>True</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue></DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 关键字
                    /// </summary>
                    case DataDefine.FieldType.KeywordType:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtKeywordSize.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radKeywordIsPCookie.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue>" + txtKeywordDefaultValue.Text.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 内容
                    /// </summary>
                    case DataDefine.FieldType.ContentType:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtContentEditorWidth.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtUploadImpType.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtUploadFlashType.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtUploadAnnexType.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlContentWsImage.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radlContentThumb.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtUploadSize.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + ddlContentFileNameRule.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue>" + txtKeywordDefaultValue.Text.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 选择用户
                    /// </summary>
                    case DataDefine.FieldType.SelectUser:
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + txtSelectUserSize.Text.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>" + radSelectUserIsPCookie.SelectedValue.Trim( ) + "</string>" + DataDefine.NewLine );
                        sbField.Append( "       <string>1</string>" + DataDefine.NewLine );
                        sbField.Append( "   <Settings>" + DataDefine.NewLine );
                        sbField.Append( "   <DefaultValue>" + txtSelectUserDefault.Text.Trim( ) + "</DefaultValue>" + DataDefine.NewLine );
                        break;
                    /// <summary>
                    /// 多图片
                    /// </summary>
                    case DataDefine.FieldType.MultiplePhotoType:
                        break;
                    /// <summary>
                    /// 多级联动
                    /// </summary>
                    case DataDefine.FieldType.LinkageType:
                        break;
                    /// <summary>
                    /// 标题
                    /// </summary>
                    case DataDefine.FieldType.TitleType:
                        break;
                    /// <summary>
                    /// 虚链接
                    /// </summary>
                    case DataDefine.FieldType.InfoType:
                        break;
                    /// <summary>
                    /// 模板
                    /// </summary>
                    case DataDefine.FieldType.TemplateType:
                        break;
                    /// <summary>
                    /// 专题
                    /// </summary>
                    case DataDefine.FieldType.SpecialType:
                        break;
                    /// <summary>
                    /// 节点
                    /// </summary>
                    case DataDefine.FieldType.NodeType:
                        break;
                    /// <summary>
                    /// 状态
                    /// </summary>
                    case DataDefine.FieldType.StatusType:
                        break;
                    /// <summary>
                    /// 风格
                    /// </summary>
                    case DataDefine.FieldType.SkinType:
                        break;
                    /// <summary>
                    /// 作者
                    /// </summary>
                    case DataDefine.FieldType.AuthorType:
                        break;
                    /// <summary>
                    /// 来源
                    /// </summary>
                    case DataDefine.FieldType.SourceType:
                        break;
                    /// <summary>
                    /// 下载服务器
                    /// </summary>
                    case DataDefine.FieldType.DownServerType:
                        break;
                    /// <summary>
                    /// 厂商
                    /// </summary>
                    case DataDefine.FieldType.Producer:
                        break;
                    /// <summary>
                    /// 品牌
                    /// </summary>
                    case DataDefine.FieldType.Trademark:
                        break;
                    /// <summary>
                    /// 商品属性
                    /// </summary>
                    case DataDefine.FieldType.Property:
                        break;
                    /// <summary>
                    /// 商品款式
                    /// </summary>
                    case DataDefine.FieldType.ProductStyle:
                        break;
                    /// <summary>
                    /// 用户名
                    /// </summary>
                    case DataDefine.FieldType.UserNameType:
                        break;
                    /// <summary>
                    /// IP地址
                    /// </summary>
                    case DataDefine.FieldType.IPType:
                        break;
                }

                sbField.Append( "   <EnableNull>" + EnableNull + "</EnableNull>" + DataDefine.NewLine );
                sbField.Append( "   <ModelId>0</ModelId>" + DataDefine.NewLine );
                sbField.Append( "</FieldInfo>" + DataDefine.NewLine );
            }

            //Model.Producer model = new GreatB2C.Model.Producer( );
            //model.ProducerID = -1;
            //model.ProducerType = Convert.ToInt32( RadlProducerType.SelectedValue.ToString( ) );
            //model.ProducerName = txtProducerName.Text.Trim( );
            //model.ProducerShortName = txtProducerShortName.Text.Trim( );
            //model.ProducerPhoto = hidImagSrc.Value.Trim( );
            //model.BirthDay = Convert.ToDateTime( txtCreateDate.Text.Trim( ) );
            //model.Address = txtAddress.Text.Trim( );
            //model.Postcode = txtPostcode.Text.Trim( );
            //model.Phone = txtPhone.Text.Trim( );
            //model.Fax = txtFax.Text.Trim( );
            //model.Email = txtEmail.Text.Trim( );
            //model.Homepage = txtHomepage.Text.Trim( );
            //model.ProducerIntro = txtProducerIntro.Text.Trim( );
            //model.LastUseTime = DateTime.Now;
            //model.Passed = false;
            //model.onTop = false;
            //model.IsElite = false;
            //model.Hits = 0;

            //bool isExist = BLL.IsExists( model );
            //if ( isExist )
            //{
            //    litScript.Text = "<script type='text/javascript'>ShowError('错误','该厂商信息已经存在，请重新输入！');</script>";
            //    return;
            //}
            //else
            //{
            //    bool isSuccess = BLL.Insert( model );
            //    if ( isSuccess )
            //    {
            //        litScript.Text = "<script type='text/javascript'>ShowInfoAndRedirect('操作成功','厂商信息添加成功！','ProducerManage.aspx');</script>";
            //        return;
            //    }
            //    else
            //    {
            //        litScript.Text = "<script type='text/javascript'>ShowError('操作失败','厂商信息添加失败！');</script>";
            //        return;
            //    }
            //}
        }

        protected void radlFieldType_SelectedIndexChanged( object sender , EventArgs e )
        {
            PnlText.Visible = false;
            PnlMultiText.Visible = false;
            PnlEditor.Visible = false;
            PhlFilter.Visible = false;
            PnlNumber.Visible = false;
            PnlCurrency.Visible = false;
            PnlDateTime.Visible = false;
            PnlLookup.Visible = false;
            PnlURL.Visible = false;
            PnlBoolean.Visible = false;
            PnlImage.Visible = false;
            PnlCurrency.Visible = false;
            PnlColor.Visible = false;
            PnlOperatingSystem.Visible = false;
            PnlRegion.Visible = false;
            PnlKeyword.Visible = false;
            PnlCurrency.Visible = false;
            PnlSelectUser.Visible = false;
            PnlMultiplePhoto.Visible = false;
            PnlLinkage.Visible = false;
            PnlTitle.Visible = false;
            PnlProperty.Visible = false;
            PhlFilter.Visible = false;
            PnlFunctions.Visible = false;

            if ( radTextType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.TextType;
                PnlText.Visible = true;
                PhlFilter.Visible = true;
                PnlFunctions.Visible = true;
            }
            else if ( radMultipleTextType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.MultipleTextType;
                PnlMultiText.Visible = true;
                PhlFilter.Visible = true;
                PnlFunctions.Visible = true;
            }
            else if ( radMultipleHtmlTextType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.MultipleHtmlTextType;
                PnlEditor.Visible = true;
                PhlFilter.Visible = true;
                PnlFunctions.Visible = true;
            }
            else if ( radListBoxType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.ListBoxType;
                PnlChoice.Visible = true;
                PhlFilter.Visible = true;
            }
            else if ( radNumberType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.NumberType;
                PnlNumber.Visible = true;
            }
            else if ( radMoneyType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.MoneyType;
                PnlCurrency.Visible = true;
            }
            else if ( radDateTimeType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.DateTimeType;
                PnlDateTime.Visible = true;
            }
            else if ( radLookType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.LookType;
                PnlLookup.Visible = true;
            }
            else if ( radLinkType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.LinkType;
                PnlURL.Visible = true;
            }
            else if ( radBoolType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.BoolType;
                PnlBoolean.Visible = true;
            }
            else if ( radPictureType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.PictureType;
                PnlImage.Visible = true;
            }
            else if ( radFileType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.FileType;
                PnlFile.Visible = true;
            }
            else if ( radColorType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.ColorType;
                PnlColor.Visible = true;
            }
            else if ( radOperatingType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.OperatingType;
                PnlOperatingSystem.Visible = true;
            }
            else if ( radRegionType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.RegionType;
                PnlRegion.Visible = true;
            }
            else if ( radKeywordType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.KeywordType;
                PnlKeyword.Visible = true;
            }
            else if ( radContentType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.ContentType;
                PnlContent.Visible = true;
            }
            else if ( radSelectUser.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.SelectUser;
                PnlSelectUser.Visible = true;
            }
            else if ( radMultiplePhotoType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.MultiplePhotoType;
                PnlMultiplePhoto.Visible = true;
            }
            else if ( radLinkageType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.LinkType;
                PnlLinkage.Visible = true;
            }
            else if ( radTitleType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.TitleType;
                PnlTitle.Visible = true;
            }
            else if ( radInfoType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.InfoType;
            }
            else if ( radTemplateType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.TemplateType;
            }
            else if ( radSpecialType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.SpecialType;
            }
            else if ( radNodeType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.NodeType;
            }
            else if ( radStatusType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.StatusType;
            }
            else if ( radSkinType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.SkinType;
            }
            else if ( radAuthorType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.AuthorType;
            }
            else if ( radSourceType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.SourceType;
            }
            else if ( radDownServerType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.DownServerType;
            }
            else if ( radProducer.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.Producer;
            }
            else if ( radTrademark.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.Trademark;
            }
            else if ( radProperty.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.Property;
                PnlProperty.Visible = true;
            }
            else if ( radProductStyle.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.ProductStyle;
            }
            else if ( radUserNameType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.UserNameType;
            }
            else if ( radIPType.Checked )
            {
                ViewState[ "FieldType" ] = DataDefine.FieldType.IPType;
            }
        }

        protected void ddlLookupTable_SelectedIndexChanged( object sender , EventArgs e )
        {
            if ( ddlLookupTable.SelectedValue.Trim( ) != "" )
            {
                ddlLookupField.Items.Clear( );

                GreatB2C.Model.Model model = new GreatB2C.Model.Model( );
                model.ModelID = Convert.ToInt32( ddlLookupTable.SelectedValue.Trim( ) );
                model = BLL.ListByID( model );
                if ( model != null )
                {
                    Component.DefaultTemplateFields dtf = new GreatB2C.Web.Component.DefaultTemplateFields( );
                    dtf.Field = model.Field;
                    DataTable dtFields = dtf.GetDataTable( "1" );
                    if ( dtFields != null && dtFields.Rows.Count > 0 )
                    {
                        ddlLookupField.DataSource = dtFields;
                        ddlLookupField.DataTextField = "FieldName";
                        ddlLookupField.DataValueField = "ID";
                        ddlLookupField.DataBind( );
                    }
                }

                ddlLookupField.Items.Insert( 0 , new ListItem( "-请选择字段-" , "" ) );
            }
        }

        protected void chkSoftSize_OnCheckedChanged( object sender , EventArgs e )
        {

        }
    }
}
